package com.learn.thread;

import java.util.concurrent.*;

public class TestThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        executorService.execute(new Task());
        executorService.execute(new Task());
        executorService.execute(new Task());
        executorService.execute(new Task());
        executorService.shutdown();

        executorService = Executors.newFixedThreadPool(3);
        System.out.println(executorService.submit(new Task2()).get());
        System.out.println(executorService.submit(new Task2()).get());
        System.out.println(executorService.submit(new Task2()).get());
        System.out.println(executorService.submit(new Task2()).get());
        executorService.shutdown();
    }
}

class Task implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}

class Task2 implements Callable<Boolean> {
    @Override
    public Boolean call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return Boolean.TRUE;
    }
}